﻿using System.Collections.Generic;
using System.Runtime.InteropServices;

namespace IntoMes.PLC
{
    /// <summary>
    /// 从PLC获取的数据
    /// </summary>
    [StructLayout(LayoutKind.Sequential, Pack = 1)]
    public class MesGetData
    {
        public bool IsConnected;
        /// <summary>
        /// 生产型号
        /// </summary>
        public int ProModel;
        /// <summary>
        /// 生产总量
        /// </summary>
        public int ProCount;
        /// <summary>
        /// 合格数量
        /// </summary>
        public int OKCount;
        /// <summary>
        /// NG数量
        /// </summary>
        public int NGCount;
        /// <summary>
        /// 生产节拍
        /// </summary>
        public int ProBeat;
        /// <summary>
        /// 设备运行时间
        /// </summary>
        public int Runtime;

        /// <summary>
        /// 设备状态
        /// </summary>
        public int DevStatus;

        /// <summary>
        /// 设备状态
        /// </summary>
        public int DevNum;
    }
    /// <summary>
    /// 下发给plc的数据
    /// </summary>
    public class MesSetData
    {
        /// <summary>
        /// 生产班次：白班，夜班
        /// </summary>
        public byte Class;
        /// <summary>
        /// 生产型号
        /// </summary>
        public byte ProModel;
        /// <summary>
        /// 计划生产数量
        /// </summary>
        public int ProCount;
    }

    [StructLayout(LayoutKind.Sequential, Pack = 1)]
    public class Display
    {
        [MarshalAs(UnmanagedType.ByValArray, SizeConst = 8)]
        public PlcToMes[] PlcDatas = new PlcToMes[8]
        {
            new PlcToMes() {Collection = new short[8]},
            new PlcToMes() {Collection = new short[8]},
            new PlcToMes() {Collection = new short[8]},
            new PlcToMes() {Collection = new short[8]},
            new PlcToMes() {Collection = new short[8]},
            new PlcToMes() {Collection = new short[8]},
            new PlcToMes() {Collection = new short[8]},
            new PlcToMes() {Collection = new short[8]},
        };
        [MarshalAs(UnmanagedType.ByValArray, SizeConst = 1)]
        public WeekDetails[] WDetails = new WeekDetails[1]
         {
                new WeekDetails() {Details = new int[7]},

          };
        public int PlanCount;
        /// <summary>
        /// 已生产数量
        /// </summary>
        public int ProductCount;



        #region  定义周，月，季度的数量

        /// <summary>
        /// 周生产数量
        /// </summary>
        public int WeekNum;

        /// <summary>
        /// 上周生产数量
        /// </summary>
        public int LastWeekNum;

        /// <summary>
        /// 月生产数量
        /// </summary>
        public int Month;
       
        /// <summary>
        /// 季度生产数量
        /// </summary>
        public int Quarter;

        /// <summary>
        /// 年度生产数量
        /// </summary>
        public int Year;


        /// <summary>
        /// 周计划生产数量
        /// </summary>
        public int WeekNumPlan;

        /// <summary>
        /// 月计划生产数量
        /// </summary>
        public int MonthPlan;


        /// <summary>
        /// 年计划生产数量
        /// </summary>
        public int YearPlan;




        #endregion

        #region  定义周，月，季度的NG数量


        /// <summary>
        /// 当天的NG生产数量
        /// </summary>
        public int NGNum;

        /// <summary>
        /// 周NG生产数量
        /// </summary>
        public int NGWeekNum;

     

        /// <summary>
        /// 月NG生产数量
        /// </summary>
        public int NGMonth;

    

        /// <summary>
        /// 年度NG生产数量
        /// </summary>
        public int NGYear;


     




        #endregion


        [MarshalAs(UnmanagedType.ByValTStr, SizeConst = 64)]
        public string Classes;
        [MarshalAs(UnmanagedType.ByValTStr, SizeConst = 64)]
        public string ProductMode;
    }

    [StructLayout(LayoutKind.Sequential, Pack = 1)]
    public struct PlcToMes
    {
        public bool PlcStatus;
        public int ProductModeFeedback;
        public int DevNum;
        [MarshalAs(UnmanagedType.ByValArray, SizeConst = 8)]
        public short[] Collection;
        public int Beat;
        public int OnlineNum;
        public int DevStatus;
    }

    [StructLayout(LayoutKind.Sequential, Pack = 1)]
    public struct WeekDetails
    {

        [MarshalAs(UnmanagedType.ByValArray, SizeConst = 7)]
        public int[] Details;

    }
}
